<?php
namespace app\api\controller\m2979\auto;

use think\Db;
use service\ApiReturn;
use app\api\controller\Base;
use app\member\service\MemberCache;


class Freegenerateinterface extends Base {

/**
 *  查询生成接口
 *@create_time  2024-03-23 14:52:56
 */
public function get_generateinterface($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];

    $order = 'freegenerateinterface.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freegenerateinterface.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freegenerateinterface.is_del', '=', 0];

    $select_info = array (
'member_user' => MemberCache::getUserListToMemberID(MemberID),
);
	$dataList = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->field("freegenerateinterface.wenben,freegenerateinterface.xitongyuangong,freegenerateinterface.create_time")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['xitongyuangong_name'] = $select_info['member_user']["{$infodataList['xitongyuangong']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

/**
 *  查询生成接口
 *@param  String[字符串]  aid  ID
 *@create_time  2024-03-28 10:19:08
 */
public function get_generateinterface1($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];

    $order = 'freegenerateinterface.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freegenerateinterface.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freegenerateinterface.is_del', '=', 0];
 	if (!empty($data['aid'])) {
		$where[] = ['freegenerateinterface.aid', '=', $data['aid']];
 	}

    $select_info = array (
'member_user' => MemberCache::getUserListToMemberID(MemberID),
);
	$dataList = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->field("freegenerateinterface.aid,freegenerateinterface.dituxuandian,freegenerateinterface.wenben,freegenerateinterface.xitongyuangong,freegenerateinterface.create_id,freegenerateinterface.create_time,freegenerateinterface.dituxuandian_province,freegenerateinterface.dituxuandian_city,freegenerateinterface.dituxuandian_district,freegenerateinterface.dituxuandian_address,freegenerateinterface.dituxuandian_lat,freegenerateinterface.dituxuandian_lng")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['xitongyuangong_name'] = $select_info['member_user']["{$infodataList['xitongyuangong']}"] ?? '';
			$infodataList['create_id_name'] = $select_info['member_user']["{$infodataList['create_id']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time'];
			$infodataList['dituxuandian_province_name'] = $infodataList['dituxuandian_province'] ?? '';
			$infodataList['dituxuandian_city_name'] = $infodataList['dituxuandian_city'] ?? '';
			$infodataList['dituxuandian_district_name'] = $infodataList['dituxuandian_district'] ?? '';
			$infodataList['dituxuandian_address_name'] = $infodataList['dituxuandian_address'] ?? '';
			$infodataList['dituxuandian_lat_name'] = $infodataList['dituxuandian_lat'] ?? '';
			$infodataList['dituxuandian_lng_name'] = $infodataList['dituxuandian_lng'] ?? '';
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

/**
 *  查询生成接口
 *@param  String[字符串]  aid  ID
 *@create_time  2024-03-30 10:16:12
 */
public function get_generateinterface123($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];

    $order = 'freegenerateinterface.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freegenerateinterface.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freegenerateinterface.is_del', '=', 0];
 	if (!empty($data['aid'])) {
		$where[] = ['freegenerateinterface.aid', '=', $data['aid']];
 	}

    $select_info = array (
);
	$dataList = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->field("freegenerateinterface.dituxuandian,freegenerateinterface.dituxuandian_province,freegenerateinterface.dituxuandian_city,freegenerateinterface.dituxuandian_district,freegenerateinterface.dituxuandian_address,freegenerateinterface.dituxuandian_lat,freegenerateinterface.dituxuandian_lng")
		->where($where)
		->order($order)
		->select();

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

/**
 *  操作生成接口
 *@param  String[字符串]  aid  ID
 *@create_time  2024-03-30 13:52:26
 */
public function test_api($data = [], $user = [])
{
    $return_data = [];

    try {
         		//入参判断生成接口
		if (!($data['aid'] != '')) {
			throw new \Exception('错误',-1);
		}
		//查询生成接口
		$order = 'freegenerateinterface.create_time desc';
		$where = [];
		$where[] = ['freegenerateinterface.is_del', '=', 0];
 		if (isset($data['aid'])) {
		$where[] = ['freegenerateinterface.aid', '=', $data['aid']];
 		}
		$query_1 = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->where($where)
		->order($order)
		->find();
		if (!($query_1)) {
			throw new \Exception('错误',-1);
		}
		//查询生成接口123
		$order = 'freegenerateinterface.create_time desc';
		$where = [];
		$where[] = ['freegenerateinterface.is_del', '=', 0];
 		if (isset($data[''])) {
		$where[] = ['freegenerateinterface.create_time', '=', $data['']];
 		}
		$query_2 = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->where($where)
		->order($order)
		->find();
		if (!($query_2)) {
			throw new \Exception('错误',-1);
		}





     } catch (\Exception $e){
        Db::rollback();
        $msg = $e->getMessage();
        $code = $e->getCode();
        return ApiReturn::r($code, [], $msg);
    }

    return ApiReturn::r(1, $return_data, '请求成功');
}

/**
 *  操作生成接口
 *@create_time  2024-04-02 15:18:15
 */
public function set_generateinterface($data = [], $user = [])
{
    $return_data = [];
    Db::startTrans();
    try {
        		//添加生成接口
		$param=[];
		$param['update_time'] = time();
		$param['create_time'] = time();
		$table = MemberCache::setTableInfoToCache(MemberID, 'lb_free_generate_interface', 'table_name');
		$auto_code_data = system_auto_code_data($param, $table);
		$param['bianma'] = $auto_code_data['bianma'] ?? '';
		$param['is_del'] = 0;
		$param['member_id'] = (isset($user['member_id']))?$user['member_id']:0;

		$query_0 = $param;
		$table_name = 'lb_free_generate_interface';
		$primary_key = 'aid';
		$res = Db::table($table_name)->insertGetId($param);
		if ($res) {
			$query_0['aid'] = $res;
		}
		if (!($res)) {
			throw new \Exception('错误',-1);
		}





        Db::commit();


    }
    catch (\Exception $e){
        Db::rollback();
        $msg = $e->getMessage();
        $code = $e->getCode();
        return ApiReturn::r($code, [], $msg);
    }

    return ApiReturn::r(1, $return_data, '请求成功');
}

/**
 *  操作生成接口
 *@param  String[字符串]  aid  ID
 *@create_time  2024-04-24 15:55:17
 */
public function set_generateinterface_fenpei($data = [], $user = [])
{
    $return_data = [];

    try {
         		//查询生成接口
		$order = 'freegenerateinterface.create_time desc';
		$where = [];
		$where[] = ['freegenerateinterface.is_del', '=', 0];
 		if (isset($data['aid'])) {
		$where[] = ['freegenerateinterface.aid', '=', $data['aid']];
 		}
		$query_0 = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->where($where)
		->order($order)
		->find();
		if (!($query_0)) {
		//添加生成接口
		$param=[];
		$param['update_time'] = time();
		$param['create_time'] = time();
		$param['fuwenben']= '1111111';
		$param['is_del'] = 0;
		$param['member_id'] = (isset($user['member_id']))?$user['member_id']:0;

		$query_2 = $param;
		$table_name = 'lb_free_generate_interface';
		$primary_key = 'aid';
		$res = Db::table($table_name)->insertGetId($param);
		if ($res) {
			$query_2['aid'] = $res;
		}
		if (!($res)) {
			throw new \Exception('错误',-1);
		}

		}
		 else{
		//更新生成接口
		$where = [];
		$where[] = ['is_del', '=', 0];
 		if (isset($data['aid'])) {
		$where[] = ['aid', '=', $data['aid']];
 		}
		$param=[];
		$param['fuwenben']= 123;
		$param['update_time'] = time();

		$table_name = 'lb_free_generate_interface';
		$query_1 = $param;
		$primary_key = 'aid';
		$res = Db::table($table_name)->where($where)->update($param);
		if (!($res)) {
			throw new \Exception('错误',-1);
		}

		}





     } catch (\Exception $e){
        Db::rollback();
        $msg = $e->getMessage();
        $code = $e->getCode();
        return ApiReturn::r($code, [], $msg);
    }

    return ApiReturn::r(1, $return_data, '请求成功');
}

/**
 *  查询生成接口
 *@create_time  2024-04-24 17:31:41
 */
public function get_generateinterface122($data = [], $user = [])
{
    $headLang  = request()->header('lang');
    $where = [];

    $order = 'freegenerateinterface.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freegenerateinterface.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freegenerateinterface.is_del', '=', 0];

    $select_info = array (
  'shenhezhuangtai' =>
  array (
    1 => '待审核',
    2 => '已通过',
    3 => '驳回',
  ),
'member_user' => MemberCache::getUserListToMemberID(MemberID),
);
	$dataList = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->field("freegenerateinterface.aid,freegenerateinterface.tupianduo,freegenerateinterface.shifen,freegenerateinterface.shoujihao,freegenerateinterface.shenhezhuangtai,freegenerateinterface.yinpin,freegenerateinterface.shipin,freegenerateinterface.xitongyuangong,freegenerateinterface.create_id,freegenerateinterface.create_time,freegenerateinterface.approve_status")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['tupianduo'] = get_files_url($infodataList['tupianduo']);
			$infodataList['shenhezhuangtai_name'] = $select_info['shenhezhuangtai']["{$infodataList['shenhezhuangtai']}"] ?? '';
			$infodataList['shipin']  = [get_file_url($infodataList['shipin'])];
			$infodataList['xitongyuangong_name'] = $select_info['member_user']["{$infodataList['xitongyuangong']}"] ?? '';
			$infodataList['create_id_name'] = $select_info['member_user']["{$infodataList['create_id']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

/**
 *  查询生成接口
 *@create_time  2024-04-24 17:34:05
 */
public function get_generateinterface2222($data = [], $user = [])
{
    p(Db::connect(Db::$config_db)->table('lb_free_notice_config')->getTableFields());

    p(member_config_com('cache_type'));
    $data = Db::name("admin_config")->where('name', '=', 'cache_type')
        ->find();
    p($data['extra']);
    p(member_config_com('cache_type'));
    $headLang  = request()->header('lang');
    $where = [];
  
    $order = 'freegenerateinterface.aid desc';
	if (!empty($data['sort_field'])) {
		$order = 'freegenerateinterface.'.$data['sort_field'].' '.$data['sort_type'];
	}

    $where[] = ['freegenerateinterface.is_del', '=', 0]; 
 
    p(get_field_property('lb_free_generate_interface','wenben'));
    
    $select_info = array (
  'wenben' =>
  array (
    1 => '1',
    2 => '2',
    3 => '3',
  ),
  'shenhezhuangtai' =>
  array (
    1 => '待审核',
    2 => '已通过',
    3 => '驳回',
  ),
'member_user' => MemberCache::getUserListToMemberID(MemberID),
);
	$dataList = Db::table('lb_free_generate_interface')
		->alias('freegenerateinterface')
		->field("freegenerateinterface.aid,freegenerateinterface.wenben,freegenerateinterface.tupianduo,freegenerateinterface.shifen,freegenerateinterface.shoujihao,freegenerateinterface.shenhezhuangtai,freegenerateinterface.yinpin,freegenerateinterface.shipin,freegenerateinterface.xitongyuangong,freegenerateinterface.create_id,freegenerateinterface.create_time,freegenerateinterface.approve_status")
		->where($where)
		->order($order)
		->select();
	foreach ($dataList as &$infodataList){
			$infodataList['wenben_name'] = $select_info['wenben']["{$infodataList['wenben']}"] ?? '';
			$infodataList['tupianduo'] = get_files_url($infodataList['tupianduo']);
			$infodataList['shenhezhuangtai_name'] = $select_info['shenhezhuangtai']["{$infodataList['shenhezhuangtai']}"] ?? '';
			$infodataList['shipin']  = [get_file_url($infodataList['shipin'])];
			$infodataList['xitongyuangong_name'] = $select_info['member_user']["{$infodataList['xitongyuangong']}"] ?? '';
			$infodataList['create_id_name'] = $select_info['member_user']["{$infodataList['create_id']}"] ?? '';
			$infodataList['create_time'] = $infodataList['create_time'];
	}

    if($dataList){
        return ApiReturn::r(1, $dataList, '请求成功');
    }else{
        return ApiReturn::r(1, [], '暂无数据');
    }
}

}